/**
 *
 */
package com.gs.practice.thread.util;

import java.util.Random;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
public class CircularArrayQueueTest {

    public static void main(String[] args) {
        final CircularArrayQueue<Integer> q = new CircularArrayQueue<>(15000000);

        final Thread reader = new Thread(
                new Runnable() {
                    Random random = new Random(Integer.MAX_VALUE);

                    @Override
                    public void run() {
                        while (true) {
                            q.dequeue();
                            /*synchronized(this){
                             try {
                             wait(500);
                             } catch (InterruptedException e) {
                             e.printStackTrace();
                             }
                             }*/
                        }
                    }
                }, "READER_THREAD"
        );

        final Thread writer = new Thread(
                new Runnable() {
                    Random random = new Random(Integer.MAX_VALUE);

                    @Override
                    public void run() {
                        while (true) {
                            q.enqueue(random.nextInt());
                            /*synchronized(this){
                             try {
                             wait(500);
                             } catch (InterruptedException e) {
                             e.printStackTrace();
                             }
                             }*/
                        }
                    }
                }, "WRITER_THREAD _ 00"
        );

        final Thread writer1 = new Thread(
                new Runnable() {
                    Random random = new Random(Integer.MAX_VALUE);

                    @Override
                    public void run() {
                        while (true) {
                            q.enqueue(random.nextInt());
                            /*synchronized(this){
                             try {
                             wait(500);
                             } catch (InterruptedException e) {
                             e.printStackTrace();
                             }
                             }*/
                        }
                    }
                }, "WRITER_THREAD _ 01"
        );

        reader.start();
        writer.start();
        writer1.start();

        Thread monitor = new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        while (true) {
                            if (Thread.State.TERMINATED == reader.getState()
                            || Thread.State.TERMINATED == writer.getState()) {
                                return;
                            }
                            System.out.println(reader.getName() + " : " + reader.getState());
                            System.out.println(writer.getName() + " : " + writer.getState());
                        }
                    }
                }, "MONITOR_THREAD"
        );

        //monitor.start();
    }

}
